﻿namespace Tower_of_hanoi
{
    internal class Program
    {
        /// <summary>
        /// 实现汉诺塔的递归运算，先实现将n-1个盘转移到B塔，再将最后一个盘转移到C塔，最后将n-1的塔由B到C
        /// </summary>
        /// <param name="x"></param>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <param name="C"></param>
        /// <returns></returns>
        static int Hanoi(int x, char A, char B, char C)
        {
            int a, b;
            if (x == 1)
            {
                Console.WriteLine("{0} -> {1}", A, C);
                return 1;
            }
            else
            {
                a = Hanoi(x - 1, A, C, B);
                Console.WriteLine("{0} -> {1}", A, C);
                b = Hanoi(x - 1, B, A, C);
                return a + b + 1;
            }
        }
        /// <summary>
        /// 输出函数的运行结果
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {

            Console.WriteLine("请输入盘数");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(Hanoi(n, 'A', 'B', 'C'));


        }
    }
}